<?php
    class memcached_helper {
        private $host;      //主机
        private $port;      //端口
        private $memcache;
    
        /*构造函数*/
        public function __construct($host, $port) {
            $this->host = $host;
            $this->port = $port;
            $this->memcache = new Memcached ( 'mystory_pool' );
            $ss = $this->memcache->getServerList ();
            if (empty ( $ss )) {
                $this->memcache->setOption(Memcached::OPT_RECV_TIMEOUT, 1000);
                $this->memcache->setOption(Memcached::OPT_SEND_TIMEOUT, 1000);
                $this->memcache->setOption(Memcached::OPT_TCP_NODELAY, true);
                $this->memcache->setOption(Memcached::OPT_SERVER_FAILURE_LIMIT, 50);
                $this->memcache->setOption(Memcached::OPT_CONNECT_TIMEOUT, 500);
                $this->memcache->setOption(Memcached::OPT_RETRY_TIMEOUT, 300);
                $this->memcache->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_CONSISTENT);
                $this->memcache->setOption(Memcached::OPT_REMOVE_FAILED_SERVERS, true);
                $this->memcache->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
                $this->memcache->addServer ( $this->host, $this->port, 1 );
            }
        }
        
        public function get_obj() {
            return $this->memcache;
        }
    }
    
    function new_memcached() {
        global $memcached_cfg;
        return new memcached_helper($memcached_cfg['host'],$memcached_cfg['port']);
    }